home *** CD-ROM | disk | FTP | other *** search
- ' This program draws one (or two) 2-point line segment with a specific distance and 3 (or 4) input points.
- ' Point 1 defines the starting endpoint of the line
- ' Point 2 and 3 define a line that contains the ending point of the 2-point line segment
- ' as well as the direction of the result line segment
- ' Point 4 is optional for drawing two lines with one on each side
- '
-
- SETPOINT "Set points: 1) Starting point, 2,3) A line that contains the ending point, [ 4) Optional for both sides", 4
- NPTS = sys(1)
- IF NPTS < 3 THEN
- END
- END IF
-
- POINTVAL CX CY CZ 1
- POINTVAL EX1 EY1 EZ1 2
- POINTVAL EX2 EY2 EZ2 3
-
- IF NPTS < 4 THEN
- A$ = "S"
- ELSE
- A$ = "D"
- END IF
-
- DX = EX2 - EX1
- DY = EY2 - EY1
- DZ = EZ2 - EZ1
- D = DX * DX + DY * DY + DZ * DZ
-
- IF D = 0 THEN
- MESSAGE "ERROR: The 2nd and 3rd points are identical."
- END
- END IF
-
- INPUT "Enter the length of the line: ", R
-
- IF R <= 0 THEN
- MESSAGE "ERROR: The length of the line must be greater than zero."
- END
- END IF
-
- VX = EX2 - EX1
- VY = EY2 - EY1
- VZ = EZ2 - EZ1
-
- R2 = R * R
-
- A = VX * VX + VY * VY + VZ * VZ
- B = 2 * (VX * (EX1 - CX) + VY * (EY1 - CY) + VZ * (EZ1 - CZ))
- C = (EX1 - CX) * (EX1 - CX) + (EY1 - CY) * (EY1 - CY) + (EZ1 - CZ) * (EZ1 - CZ) - R2
-
- D = B * B - 4 * A * C
-
- IF D < 0 THEN
- MESSAGE "ERROR: Cannot draw the line with the input points."
- END
- END IF
-
- D = SQRT(D)
- A = 2 * A
-
- T1 = (D - B) / A
- T2 = -(B + D) / A
-
- X1 = EX1 + T1 * VX
- Y1 = EY1 + T1 * VY
- Z1 = EZ1 + T1 * VZ
-
- X2 = EX1 + T2 * VX
- Y2 = EY1 + T2 * VY
- Z2 = EZ1 + T2 * VZ
-
- IF A$ = "D" THEN
- >LINE
- {
- <POINTXYZ [CX, CY, CZ]
- <POINTXYZ [X1, Y1, Z1]
- }
- >LINE
- {
- <POINTXYZ [CX, CY, CZ]
- <POINTXYZ [X2, Y2, Z2]
- }
- ELSE
- DX = X2 - X1
- DY = Y2 - Y1
- DZ = Z2 - Z1
- D = DX * VX + DY * VY + DZ * VZ
-
- IF D < 0 THEN
- >LINE
- {
- <POINTXYZ [CX, CY, CZ]
- <POINTXYZ [X1, Y1, Z1]
- }
- ELSE
- >LINE
- {
- <POINTXYZ [CX, CY, CZ]
- <POINTXYZ [X2, Y2, Z2]
- }
- END IF
- END IF
-
-